<template>
  <div class="my-reply">
    <div class="white-box" @click="popupShow">请发表你的看法...</div>
    <popup v-model="replyShow">
      <div class="popup">
        <div class="action-btn">
          <div class="cancel" @click="popupCancel">取消</div>
          <div class="title">回复</div>
          <div class="submit green" @click="onReply">提交</div>
        </div>
        <div>
          <x-textarea
            placeholder="请发表你的看法..."
            :rows="5"
            v-model="myReplyContent"></x-textarea>
        </div>
      </div>
    </popup>
  </div>
</template>

<script>
export default {
  name: "my-reply",
  props: {
    detailId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      replyShow: false,
      myReplyContent: '',
    }
  },
  /*directives: {
    focus: {
      update: (el,{value}) => {
        if (value) {
          const textEl = el.getElementsByTagName('textarea')[0]
          textEl.focus()
        }
      }
    }
  },*/
  methods: {
    popupShow() {
      this.replyShow = true
    },
    popupCancel() {
      this.replyShow = false
    },
    async onReply() {
      const res = await this.$post('/discovery/articleReply',{
        id: this.detailId,
        replyContent: this.myReplyContent
      }, true)
      if (res.code === 1) {
        this.$vux.toast.text(res.codeMessage)
        this.popupCancel()
      }
    }
  }
}
</script>

<style scoped lang="less">
@import "../style/var";

.my-reply {
  flex: 0 0 112px;
  border-top: 1px solid @gray;
  background-color: @gray-light;
  .white-box {
    width: 92%;
    margin: 20px auto 0;
    background-color: #fff;
    border-radius: 8px;
    border: 1px solid @gray-light;
    line-height: 2.2;
    padding-left: 10px;
    color: @gray;
  }
}

.popup {
  background-color: #fff;
  .action-btn {
    position: relative;
    text-align: center;
    font-size: 32px;
    line-height: 2.5;
    .border-bottom();
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;

    .title {
      font-size: 36px;
      font-weight: bold;
    }

    /*.cancel{
      left: 20px;
    }
    .submit{
      right: 20px;
    }
    .cancel,.submit{
      position: absolute;
      top: 20px;
      line-height: 1;
    }*/
  }
}
</style>
